<? 

include("config.php") ; 


for($i = 0 ; $i > 12 ; $i ++ )
{ 



$commands = file_get_contents($url_server."?key=".$key) ; 
$return = explode("\n",$commands) ;


//print_r($return) ; 
//echo sizeof($return) ; 

// get commands 
$i = 0  ; 
if(sizeof($return) > 1 )
{ 

	foreach ($return as $row)
	{

		// clean return string 
		$row = str_replace("\t","",$row) ;
		$row = ltrim($row) ;
		
		
		if($row != "" )
		{ 
			//echo $row."---".strlen($row)."\n" ; 
			
			if($row == "2033")
			{ 
				echo "invalid key" ; 
				exit(); 
				
			}
			else if($row == "2035")
			{
				echo "nothing to do !!!" ;
				exit();
			
			}
			else
			{ 
				$piece_row = explode("*",$row) ; 
					
				$array_execute[$i]['id'] = $piece_row[0] ; 
				$array_execute[$i]['command'] = $piece_row[1] ;
				$i ++ ;
				
			}
			
			
		}
		 
	}
	
	
	
}


// run commands
for($i = 0 ; sizeof($array_execute) > $i ; $i ++ )
{  
	//echo $array_execute[$i]['command'] ; 
	
	putenv("LC_CTYPE=en_US.UTF-8");
		
	exec($array_execute[$i]['command']." 2>&1", $output, $returnStatus);
	if ( $returnStatus )
	{
		print_r($output);
	}else
	{ 
		$return = urlencode(implode("*",$output)) ;
		$url_post = $url_server."return/?key=".$key."&id=".$array_execute[$i]['id']."&return=".$return ; 
		$commands = file_get_contents($url_post) ;
	}
	
}

sleep(5) ; 

} 


?> 